package com.gaohe.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gaohe.common.R;
import com.gaohe.pojo.Comment;
import com.gaohe.service.CommentService;
import com.gaohe.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @Autowired
    private ShopService shopService;

    @GetMapping("/getCommentsByShopId/{id}")
    public R getCommentsByShopId(@PathVariable Long id){
        LambdaQueryWrapper<Comment>lqw = new LambdaQueryWrapper<>();
        lqw.eq(Comment::getShopId,id);
        return R.success(commentService.list(lqw));
    }

    //    删除数据
    @DeleteMapping
    public R delete(Long id){
        LambdaQueryWrapper<Comment> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Comment::getShopId,id);
        commentService.remove(lqw);
        return shopService.removeById(id) ? R.success("删除成功"):R.error("删除失败");
    }


}
